package pe.gob.osinergmin.interfase_siaf.dac.common.dao.impl;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import pe.gob.osinergmin.interfase_siaf.dac.common.dao.IntfNotDao;
import pe.gob.osinergmin.interfase_siaf.dac.domain.interfase.IntfNot;


@Repository("intfNotDao")
public class IntfNotDaoImpl implements IntfNotDao {
	
    private final Log logger = LogFactory.getLog(getClass());
 	
	
	private NamedParameterJdbcTemplate jdbcParameterTemplateInterfase;	
	//private JdbcTemplate jdbcTemplateInterfase;		
	
	
	@Autowired
	public void SetDataSource(DataSource dataSourceInterfase){
		//this.jdbcTemplateInterfase = new JdbcTemplate(dataSourceInterfase);
		this.jdbcParameterTemplateInterfase = new NamedParameterJdbcTemplate(dataSourceInterfase);		
	}
	
	
	
	/**DECLARACION DE SQL**/	
	/*private static final String SQL_INSERT_INTF_NOT ="INSERT INTO INTF_NOT (SECUENCIAL,CORRELATIV,NOTA,DATO_ORI) "
			+ " VALUES (:secuencial, :correlativ, :nota, :datoOri)";
	*/
	//private static final String SQL_SELECT_SECUENCIAL="SELECT secuencial FROM INTF_NOT WHERE secuencial=:secuencial";
	
	private static final String SQL_SELECT_SECUENCIAL="SELECT COUNT(secuencial) FROM INTF_NOT WHERE secuencial=:secuencial";
	
	/**IMPLEMENTACION DE METODOS*/
	
	/*@Override
	public void insertarIntfNot(IntfNot intfNot) throws Exception{
		logger.info("Ingresando a insertar intfNot"); 
		SqlParameterSource parameters = new BeanPropertySqlParameterSource(intfNot);
		int ok = this.jdbcParameterTemplateInterfase.update(SQL_INSERT_INTF_NOT, parameters);
		logger.info("insertar intfNot OK :  " + ok); 
	}*/
	
	
	@Override
	public int verificarSecuencialNot(IntfNot n) throws Exception {	
		logger.info("ingresnado a verificar el secuencial de intf_not"); 
		SqlParameterSource parameters = new BeanPropertySqlParameterSource(n);			
	    return this.jdbcParameterTemplateInterfase.queryForInt(SQL_SELECT_SECUENCIAL, parameters);	
	}

}
